import React, { useState, useEffect } from 'react'
import { getMyHouseList } from '@/api/rent'
import HouseItem from '@/components/HouseItem'
import MyNavBar from '@/components/MyNavBar'

function Rent () {
  const [houseList, setHouseList] = useState(null)

  useEffect(() => {
    async function getMyHouseListData () {
      const res = await getMyHouseList()

      if (res.data.status === 200) {
        setHouseList(res.data.body)
      }
    }

    getMyHouseListData()
  }, [])

  return (
    <div>
      <MyNavBar>我的出租列表</MyNavBar>
      {houseList &&
        houseList.map(item => {
          return <HouseItem key={item.houseCode} {...item} />
        })}
    </div>
  )
}

export default Rent
